package com.ithzl.capacity.service.impl;

import com.ithzl.capacity.mapper.UserMapper;
import com.ithzl.capacity.pojo.User;
import com.ithzl.capacity.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    UserMapper userMapper;
    @Override
    public User login(String number, String password) {

        // 获取对象
        User user=userMapper.getUserByAccessionNumber(number);

        // 有则判断密码是否正确
        if (user!=null){
            BCryptPasswordEncoder bCryptPasswordEncoder=new BCryptPasswordEncoder();
            String userPassword=user.getPassword();
            if (bCryptPasswordEncoder.matches(password,userPassword)){
                return user;
            }
        }
        return null;
    }
}
